﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;
using Com.Rivyer.BLL;
using Com.Rivyer.Model;

namespace Com.Rivyer.Web.personal
{
    public partial class changepwd : System.Web.UI.Page
    {
        private readonly userBll userbll = new userBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            //非法操作验证
            if (Session["username"] == null
                || Session["username"].ToString().Trim().Length == 0)
            {
                Response.Write("<script>top.location='../login.aspx'</script>");
            }
            username.Text = Session["username"].ToString();
        }

        protected void confirm_Click(object sender, EventArgs e)
        {
            //验证模块
            if (newpwd.Text != confirmpwd.Text)
            {
                MessageBox.Show(this, "新密码与确认密码不相符!");
            }
            else if (newpwd.Text.Length < 5)
            {
                MessageBox.Show(this, "新密码不能少于5个字符,至少六个!");
            }
            else if (newpwd.Text == originpwd.Text)
            {
                MessageBox.Show(this, "新旧密码不能够一样!");
            }
            else
            {
                if (userbll.changePwd(Session["username"].ToString(), newpwd.Text, originpwd.Text))
                {
                    Maticsoft.Common.MessageBox.Show(this,"密码修改成功,请以后用新密码登录!");
                }
                else
                {
                    MessageBox.Show(this, "提供的旧密码不正确!");
                }
            }
        }
    }
}